package com.seres.feign.validator.validator;

import cn.hutool.core.util.ReUtil;
import com.seres.feign.validator.annotation.Mobile;
import com.seres.util.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @Description : 电话号码验证器
 * @ClassName : MobileValidator
 * @Author : 程磊
 * @Date: 2020-07-06 17:22
 */
public class MobileValidator implements ConstraintValidator<Mobile, String> {

    private String regexp;
    @Override
    public void initialize(Mobile constraintAnnotation) {
        this.regexp = constraintAnnotation.regexp();
    }

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        if(StringUtils.isBlank(s)){
            return false;
        }
        return ReUtil.isMatch(this.regexp,s);
    }
}
